package cn.tedu._05mvc.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class BMIController {
    @RequestMapping("/bmi")
    @ResponseBody
    public String bmi(Double height, Double weight){
        System.out.println(height + ":" + weight); //打印只是为了测试;
        double bmi = weight / (height * height);
        if (bmi < 18.5) {
            return "兄弟,你瘦了";
        }
        if (bmi < 24){
            return "兄弟,你很棒";
        }
        if (bmi < 27){
            return "兄弟,你微胖了";
        }

        return "兄弟,你胖了";
    }
    @GetMapping("/bmi/{height}/{weight}")
    @ResponseBody
    public String bmi2(@PathVariable Double height, @PathVariable Double weight){
        System.out.println(height + ":" + weight); //打印只是为了测试;
        double bmi = weight / (height * height);
        if (bmi < 18.5) {
            return "兄弟,你瘦了";
        }
        if (bmi < 24){
            return "兄弟,你很棒";
        }
        if (bmi < 27){
            return "兄弟,你微胖了";
        }

        return "兄弟,你胖了";
    }
    /**
     * 路径中传递数据
     * 1.请求路径: /bmi/{height}/{weight}
     * 2.请求方法: GET
     * 3.请求参数: height,weight
     * 4.参数类型: 路径参数
     * 5.返回响应: 字符串类型;
     * 测试: http://localhost:8080/bmi/1.7/80.0
     */

}

